/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package template;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Rabid
 */
public abstract class RegistrantionPanel extends javax.swing.JPanel {

    public void resetValue() {
        List<Component> i = getIdentityComponent();
        List<Component> e = getEsentialComponent();
        List<Component> o = getOtherComponent();

        for (Component IC : i) {
            if (IC.getClass() == javax.swing.JTextField.class) {
                ((JTextField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JPasswordField.class) {
                ((JPasswordField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JFormattedTextField.class) {
                ((JFormattedTextField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JComboBox.class) {
                ((JComboBox) IC).setSelectedItem(null);
            } else if (IC.getClass() == javax.swing.JTextArea.class) {
                ((JTextArea) IC).setText("");
            } else if (IC.getClass() == javax.swing.JTable.class) {
                ((JTable) IC).removeAll();
            }
        }

        for (Component IC : e) {
            if (IC.getClass() == javax.swing.JTextField.class) {
                ((JTextField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JPasswordField.class) {
                ((JPasswordField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JFormattedTextField.class) {
                ((JFormattedTextField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JComboBox.class) {
                ((JComboBox) IC).setSelectedItem(null);
            } else if (IC.getClass() == javax.swing.JTextArea.class) {
                ((JTextArea) IC).setText("");
            } else if (IC.getClass() == javax.swing.JTable.class) {
                ((JTable) IC).removeAll();
            }
        }

        for (Component IC : o) {
            if (IC.getClass() == javax.swing.JTextField.class) {
                ((JTextField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JPasswordField.class) {
                ((JPasswordField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JFormattedTextField.class) {
                ((JFormattedTextField) IC).setText("");
            } else if (IC.getClass() == javax.swing.JComboBox.class) {
                ((JComboBox) IC).setSelectedItem(null);
            } else if (IC.getClass() == javax.swing.JTextArea.class) {
                ((JTextArea) IC).setText("");
            } else if (IC.getClass() == javax.swing.JTable.class) {
                ((JTable) IC).removeAll();
            }
        }
    }

    boolean checkRequeredComponent() {
        List<Component> i = getIdentityComponent();
        List<Component> e = getEsentialComponent();
        boolean b = true;
        for (Component IC : i) {
            if (IC.getClass() == javax.swing.JTextField.class && ((JTextField) IC).getText().isEmpty()) {
                    b = false;
                
            }
            else if (IC.getClass() == javax.swing.JPasswordField.class && ((JPasswordField) IC).getText().isEmpty()) {
                    b = false;
            }
            else if (IC.getClass() == javax.swing.JTextArea.class && ((JTextArea) IC).getText().isEmpty()) {
                    b = false;
            }
            else if (IC.getClass() == javax.swing.JFormattedTextField.class && ((JFormattedTextField) IC).getText().isEmpty()) {
                    b = false;
            }
            else if (IC.getClass() == javax.swing.JTable.class && ((JTable) IC).getRowCount() < 1) {
                    b = false;
            }
            else if (IC.getClass() == javax.swing.JList.class && ((JList) IC).getVisibleRowCount() < 1) {
                    b = false;
            }
            else if (IC.getClass() == javax.swing.JComboBox.class && ((JComboBox) IC).getSelectedItem() == null) {
                    b = false;
            }
            
        }

        for (Component IC : e) {
            if (IC.getClass() == javax.swing.JTextField.class
                    || IC.getClass() == javax.swing.JPasswordField.class
                    || IC.getClass() == javax.swing.JTextArea.class
                    || IC.getClass() == javax.swing.JTable.class
                    || IC.getClass() == javax.swing.JList.class
                    || IC.getClass() == javax.swing.JFormattedTextField.class
                    || IC.getClass() == javax.swing.JComboBox.class) {
                if (((JTextField) IC).getText().isEmpty()) {
                    b = false;
                } else if (((JPasswordField) IC).getText().isEmpty()) {
                    b = false;
                } else if (((JFormattedTextField) IC).getText().isEmpty()) {
                    b = false;
                } else if (((JTextArea) IC).getText().isEmpty()) {
                    b = false;
                } else if (((JTable) IC).getRowCount() < 1) {
                    b = false;
                } else if (((JList) IC).getVisibleRowCount() < 1) {
                    b = false;
                } else if (((JComboBox) IC).getSelectedItem() == null) {
                    b = false;
                }
            }
        }
        if (!b) {
            JOptionPane.showMessageDialog(null, "One or more requered field is empty..");
        }
        return b;
    }

    public abstract List<Component> getIdentityComponent();

    public abstract List<Component> getEsentialComponent();

    public abstract List<Component> getOtherComponent();

    public abstract Object initObject();

    public Object[] initObjectList() {
        return null;
    }

    public abstract void getUnbindObject(Object object);

    public abstract void bindComponents(ArrayList<Object> list, int index);

    /**
     * Create Grab focus list<br/><br/>
     * public List<Component> componentList(){<br/>
     * <B>&nbtb; return Arrays.asList(<br/>
     * &nbtb; &nbtb;txtCode,<br/>
     * &nbtb; &nbtb;txtName<br/>
     * &nbtb; );</B><br/> }
     */
    public abstract List<Component> componentList();
}
